package repalcetest;

import java.util.regex.Pattern;

public class ReplaceAllTest {

  public static void main(String[] args) throws java.lang.Exception {

    System.out.println(Integer.parseInt("004AB", 16));
/***
 * 1282
 * 729
 * 288
 */
    stringWithReplaceStarFlag();
    stringWithReplacePlusFlag();
    stringWithReplaceRegexComplie();
  }

  private static void stringWithReplaceStarFlag() {
    long start = System.currentTimeMillis();

    for (int i = 0; i < 300000; i++) {
      String a = "  54,303,14311.34320  32,03254   ".replaceAll("[,. ]*", "");
      if (i == 0) {
        System.out.println(a);
      }
    }

    long end = System.currentTimeMillis();

    System.out.println(end - start);
  }

  private static void stringWithReplacePlusFlag() {
    long start = System.currentTimeMillis();

    for (int i = 0; i < 300000; i++) {
      String a = "  54,303,14311.34320  32,03254   ".replaceAll("[,. ]+", "");
      if (i == 0) {
        System.out.println(a);
      }
    }

    long end = System.currentTimeMillis();

    System.out.println(end - start);
  }

  private static void stringWithReplaceRegexComplie() {
    Pattern p = Pattern.compile("[,. ]+");
    long start = System.currentTimeMillis();

    for (int i = 0; i < 300000; i++) {
      String a = p.matcher("  54,303,14311.34320  320,3254   ").replaceAll("");
      if (i == 0) {
        System.out.println(a);
      }
    }

    long end = System.currentTimeMillis();

    System.out.println(end - start);
  }
}
